<?php

namespace Controller\Ajax;

class Base extends \Lib\Core\Ajax {
    
    public $mustLogin = true;

    public $accountId;
    
    /**
     * 判断是否登录
     */
    public function __construct() {
        $this->getCurrentAccount();
        if ($this->mustLogin) {
            $this->mustLogin();
        }
    }
    
    /**
     * 根据Id判断用户是否登录
     * 
     * @return boolean
     */
      protected function mustLogin() {
        if (!$this->accountId) {
            $url = '/Passport/Login';
            \Lib\Util\Comm::redirect($url);
        }
        return true;
    }
    
    /**
     * 获取用户登录的Id
     * 
     * @return type
     */
    private function getCurrentAccount() {
        $id = \Util\Account::getAccountIdToCookie();
        if (!$id) {
            return;
        }
        $this->accountId = $id;
    }
}